//package yb.ecp.fast.infra.nacos;
//
//import com.alibaba.cloud.commons.lang.StringUtils;
//import com.fasterxml.jackson.core.JsonProcessingException;
//import com.fasterxml.jackson.databind.JsonNode;
//import com.fasterxml.jackson.databind.ObjectMapper;
//import com.fasterxml.jackson.databind.SerializationFeature;
//import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
//import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
//import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
//import lombok.extern.slf4j.Slf4j;
//
//import java.io.IOException;
//import java.io.StringWriter;
//
//@Slf4j
//public class YamlUtil {
//    /**
//     * 将yaml字符串转成类对象
//     *
//     * @param yamlStr 字符串
//     * @param clazz   目标类
//     * @param <T>     泛型
//     * @return 目标类
//     */
//    public static <T> T toBean(String yamlStr, Class<T> clazz) {
//        if (StringUtils.isBlank(yamlStr)) {
//            return null;
//        }
//        ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
//        mapper.findAndRegisterModules();
//        try {
//            return mapper.readValue(yamlStr, clazz);
//        } catch (JsonProcessingException e) {
//            log.error("", e);
//        }
//        return null;
//    }
//
//    /**
//     * 将类对象转yaml字符串
//     *
//     * @param object 对象
//     * @return yaml字符串
//     */
//    public static String toYaml(Object object) {
//        ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
//        mapper.findAndRegisterModules();
//        mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
//        mapper = new ObjectMapper(new YAMLFactory().disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER));
//        StringWriter stringWriter = new StringWriter();
//        try {
//            mapper.writeValue(stringWriter, object);
//            return stringWriter.toString();
//        } catch (IOException e) {
//            log.error("", e);
//        }
//        return null;
//    }
//
//    /**
//     * 将json转为yaml
//     * json 2 yaml
//     *
//     * @param jsonStr json
//     * @return yaml
//     * @throws JsonProcessingException Exception
//     */
//    public static String json2Yaml(String jsonStr) throws JsonProcessingException {
//        JsonNode jsonNode = new ObjectMapper().readTree(jsonStr);
//        return new YAMLMapper().writeValueAsString(jsonNode);
//    }
//}
